package com.liucxu.jiandanl.Business;

import com.google.gson.Gson;
import com.liucxu.jiandanl.Consts.Urls;
import com.liucxu.jiandanl.Entity.GirlEntity;
import com.liucxu.jiandanl.Http.RequestManager;
import com.liucxu.jiandanl.Interface.RequestCallbackInterface;

import java.util.List;

import de.greenrobot.event.EventBus;


/**
 * 获取福利的Event
 * Created by liuchenxu on 2016/8/4.
 */
public class GirlsEvent extends BaseEvent {

    private boolean error;

    private List<GirlEntity> results ;

    public boolean isError() {
        return error;
    }

    public void setError(boolean error) {
        this.error = error;
    }

    public List<GirlEntity> getResults() {
        return results;
    }

    public void setResults(List<GirlEntity> results) {
        this.results = results;
    }

    /**
     * 获取福利的方法
     * @param pageIndex
     */
    public static void GetGirlsByPage(int pageIndex){

        RequestManager.GET(Urls.GIRLS_URL + pageIndex, new RequestCallbackInterface() {
            @Override
            public void onSuccess(String response) {
                GirlsEvent event=(new Gson()).fromJson(response,GirlsEvent.class);
                event.setResultCode(1);
                EventBus.getDefault().post(event);
            }

            @Override
            public void onFail() {
                GirlsEvent event=new GirlsEvent();
                event.setResultCode(0);
                EventBus.getDefault().post(event);
            }
        });
    }
}
